﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HotelManagement.DTO;
using HotelManagement.DAO;

namespace HotelManagement.BLO
{
    class EquipmentBLO
    {
        private EquipmentDAO dao;
        public EquipmentDAO Dao
        {
            get { return dao; }
            set { dao = value; }
        }

        public EquipmentBLO()
        {
            dao = new EquipmentDAO();
        }

        public bool Insert(EqiupmentDTO equip)
        {
            return dao.Insert(equip);
        }

        public bool Update(EqiupmentDTO equip)
        {
            return dao.Update(equip);
        }

        public DataTable Select()
        {
            return dao.Select();
        }

        public EqiupmentDTO GetEquipmentIDFromName(string pEquipmentName)
        {
            EqiupmentDTO unt = new EqiupmentDTO();
            unt.EquipmentID = 0;
            DataTable tbl = this.Select();
            foreach (DataRow row in tbl.Rows)
            {
                if (row["EquipmentName"].ToString()==pEquipmentName)
                {
                    System.Windows.Forms.MessageBox.Show(pEquipmentName,"xxxxxxxxxxxxxxxx");
                    unt.EquipmentID = int.Parse(row["EquipmentID"].ToString());
                    unt.EquipmentName = row["EquipmentName"].ToString();
                    break;
                }
            }
            if (unt.EquipmentID<=0)
            {
                return null;
            }
            return unt;
        }
        public string GetEquipmentNameFromID(int pID)
        {
            if (pID==0)
            {
                return "";
            }
            DataTable tbl = this.Select();
            foreach (DataRow row in tbl.Rows)
            {
                if (int.Parse(row["EquipmentID"].ToString())==pID)
                {
                    return row["EquipmentName"].ToString();
                }
            }
            return "";
        }
    }
}
